﻿using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;

namespace ForumReader
{
    public static class ControlExtensions
    {
        private const int WM_CHANGEUISTATE = 0x127;
        private const int UIS_SET = 1;
        private const int UIS_CLEAR = 2;
        private const int UIS_INITIALIZE = 3;
        private const int UISF_ACTIVE = 0x4;
        private const int UISF_HIDEACCEL = 0x2;
        private const int UISF_HIDEFOCUS = 0x1;

        [DllImport("user32.dll")]
        private static extern int SendMessage(IntPtr hWnd, int msg, int wParam, int lParam);

        public static void HideFocus(this Control control)
        {
            SendMessage(control.Handle, WM_CHANGEUISTATE, UIS_SET | (UISF_HIDEFOCUS << 16), 0);
        }

        [DllImport("uxtheme", ExactSpelling=true, CharSet=CharSet.Unicode)]
        public extern static int SetWindowTheme(IntPtr hWnd, string textSubAppName, string textSubIdList);

        public static void SetWindowTheme(this Control control, string theme)
        {
            SetWindowTheme(control.Handle, theme, null);
        }
    }
}
